package edu.ec.java02.group02.service.impl;

import edu.ec.java02.group02.domain.Cart;
import edu.ec.java02.group02.mapper.CartMapper;
import edu.ec.java02.group02.model.CartDetail;
import edu.ec.java02.group02.service.CartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CartServiceImpl implements CartService {

    @Resource
    CartMapper cartMapper;

    @Override
    public boolean addCart(Cart cart) {
        return cartMapper.addCart(cart);
    }

    @Override
    public boolean findProductById(Integer uid, Integer pid) {
        if(cartMapper.findProductById(uid,pid) != null)
            return true;
        return false;
    }

    @Override
    public boolean updateCart(Cart cart) {
        return cartMapper.updateCart(cart);
    }

    @Override
    public List<Cart> findCartInfoById(Integer uid) {
        return cartMapper.findCartInfoById(uid);
    }

    @Override
    public boolean delProduct(Integer uid, String[] ids) {
        int pid=0;
        for(int i=0;i<ids.length;i++){
            pid=Integer.parseInt(ids[i]);
            Cart c = new Cart();
            c.setUserId(uid);
            c.setProductId(pid);
            if(!cartMapper.delProduct(c))
                return false;
        }
        return true;
    }

//    @Override
//    public boolean delProduct(Cart cart) {
//        return cartMapper.delProduct(cart);
//    }


}
